package jdbc;

import jdbc.common.InputUtil;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Scanner;

public class RegUserDemo {
    public static void main(String[] args) throws Exception{
        UserInfo userinfo= InputUtil.getInputObject(new UserInfo());
        System.out.println(userinfo);
        Connection connection=DBUtil.getConnection();
        System.out.println("链接成功");
        Statement statement=connection.createStatement();
        String sql="INSERT INTO userinfo(username,password,nickname,age)\n" +
                "VALUES ('"+userinfo.getUsername()+"','"+userinfo.getPassword()+"','"+userinfo.getNickname()+"','"+userinfo.getAge()+"')";
        int num=statement.executeUpdate(sql);
        System.out.println(num>0?"注册成功":"注册失败");
        connection.close();
    }
}
